import { createApp } from 'vue'
import App from './App.vue'
import router from "@/router";
import {checkUserLoginStatus} from "@/tool";

const app = createApp(App);

// 引入elementui
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import "element-plus/theme-chalk/display.css";
// import "./assets/style/element-variables.scss";
app.use(ElementPlus);

import "./assets/style/iconfont.css";

//全局前置守卫
router.beforeEach((to, from, next) => {
    // document.title = "点餐管理";

    if (to.name === "Login") {
        next();
    } else {
        if (!checkUserLoginStatus()) {
            next("/login");
        } else {
            next();
        }
    }
});

router.beforeEach(() => {})

//引入cookies
import VueCookies from "vue-cookies";
app.config.globalProperties.$VueCookies = VueCookies;

import * as ElementPlusIconsVue from '@element-plus/icons-vue'

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.use(router).mount('#app')
